#include <iostream>
#include <string>

class Test
{
public:
    Test(std::string str);
    ~Test();

    void func1() const;
    void func2();

private:
    std::string str;
};

Test::Test(std::string str1)
{
    str = str1;
    std::cout << __LINE__ << str << std::endl;
}

Test::~Test()
{};

void Test::func1() const
{
    std::cout << str << std::endl;
}

void Test::func2()
{
    std::cout << str + " world" << std::endl;
}

int main()
{
    Test val("hello");
    val.func1();
    val.func2();

    const Test val2("hello");
    val2.func1();
    // val2.func2(); // 错误，只能调用const声明的成员函数

    return 0;
}
